package com.tjmc.finance.controller;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tjmc.finance.service.UsageItemExchangeConfService;
import com.tjmc.recruit.common.core.util.R;
import com.tjmc.recruit.common.log.annotation.SysLog;
import com.tjmc.recruit.finance.api.entity.UsageItemExchangeConfEntity;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

/**
 * 消费项兑换配置表
 *
 * @author recruit
 * @date 2024-11-25 16:38:45
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/usageItemExchangeConf" )
@Tag(description = "usageItemExchangeConf" , name = "消费项兑换配置表管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class UsageItemExchangeConfController {

    private final UsageItemExchangeConfService usageItemExchangeConfService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param usageItemExchangeConf 消费项兑换配置表
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    public R getUsageItemExchangeConfPage(@ParameterObject Page page, @ParameterObject UsageItemExchangeConfEntity usageItemExchangeConf) {
        LambdaQueryWrapper<UsageItemExchangeConfEntity> wrapper = Wrappers.lambdaQuery(usageItemExchangeConf);
        return R.ok(usageItemExchangeConfService.page(page, wrapper));
    }


    /**
     * 通过条件查询消费项兑换配置表
     * @param usageItemExchangeConf 查询条件
     * @return R  对象列表
     */
    @Operation(summary = "通过条件查询" , description = "通过条件查询对象" )
    @GetMapping("/details" )
    public R getDetails(@ParameterObject UsageItemExchangeConfEntity usageItemExchangeConf) {
        return R.ok(usageItemExchangeConfService.list(Wrappers.query(usageItemExchangeConf)));
    }

    /**
     * 新增消费项兑换配置表
     * @param usageItemExchangeConf 消费项兑换配置表
     * @return R
     */
    @Operation(summary = "新增消费项兑换配置表" , description = "新增消费项兑换配置表" )
    @SysLog("新增消费项兑换配置表" )
    @PostMapping
    public R save(@RequestBody UsageItemExchangeConfEntity usageItemExchangeConf) {
        return R.ok(usageItemExchangeConfService.save(usageItemExchangeConf));
    }

    /**
     * 修改消费项兑换配置表
     * @param usageItemExchangeConf 消费项兑换配置表
     * @return R
     */
    @Operation(summary = "修改消费项兑换配置表" , description = "修改消费项兑换配置表" )
    @SysLog("修改消费项兑换配置表" )
    @PutMapping
    public R updateById(@RequestBody UsageItemExchangeConfEntity usageItemExchangeConf) {
        return R.ok(usageItemExchangeConfService.updateById(usageItemExchangeConf));
    }

    /**
     * 通过id删除消费项兑换配置表
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除消费项兑换配置表" , description = "通过id删除消费项兑换配置表" )
    @SysLog("通过id删除消费项兑换配置表" )
    @DeleteMapping
    public R removeById(@RequestBody Integer[] ids) {
        return R.ok(usageItemExchangeConfService.removeBatchByIds(CollUtil.toList(ids)));
    }
}
